<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\select2\Select2;
use app\modules\Cruise\models\Cruise;
use dosamigos\tinymce\TinyMce;
use kartik\sortable\Sortable;
use kartik\sortinput\SortableInput;
use yii\widgets\Pjax;

?>

<div id="mask">
<?PHP Pjax::begin(['enablePushState'=>false, 'id'=>'trip', 'timeout'=>3000, 'linkSelector'=>'#sortAction, #saveAction']);?>
    <?php $form = ActiveForm::begin([
        'action' => ['sort'],
        'id' => 'sortAction',
        'method' => 'get',
        'layout' => 'inline',
        'options' => ['data-pjax'=>true],
    ]); ?>
    <input type="hidden" name="id" value="<?= $model->id ?>">

    <?php 
        echo SortableInput::widget([
            'name'=> 'sort',
            'id'=> 'sort',
            'items' => $example, 
            'sortableOptions' => [
                'itemOptions'=>['class'=>'alert alert-success'],
                'type'=> Sortable::TYPE_GRID,
                'pluginEvents' => ["sortupdate" => "function() {}"]
            ],
            'hideInput' => true,
        ]);
    ?>
    <?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-primary']) ?>
    <?= Html::a(Yii::t('app', '返回航线详情'), ['view', 'id'=>$model->id ], ['class' => 'btn btn-danger pull-right']) ?>
    <?php ActiveForm::end(); ?>


    <?php $form = ActiveForm::begin([
        'action' => ['save'], 'id'=>'saveAction', 'method' => 'post', 'options' => ['data-pjax'=>true],
    ]); ?>
    <input type="hidden" name="id" value="<?= $model->id ?>">

    <div class="form-horizontal">
        <h3 class="page-header"><?= $model->name ?>&nbsp;<small><?= $model->go_time ?> / <?= $model->return_time ?></small></h3>
        <?php foreach($data as $key=>$val){ 
            echo $this->render('_trip_item', ['val' => $val , 'i'=>$key ,'id'=>$model->id,'trip_img'=>$model->trip_img]);
        } ?>
    </div>
    <hr>
    <div class="text-center"><?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-primary']) ?></div>
    <?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</div>


<?php app\components\JsBlock::begin() ?>
<script type="text/javascript">  
/**  add Loading  **/
$(document).on('pjax:send', function() {
    //$('.loading-pjax').addClass('loading-pjax-style');
})
$(document).on('pjax:complete', function() {
    //$('.loading-pjax').removeClass('loading-pjax-style');
    alert("保存完成");
    window.location.reload();
})
</script>
<?php app\components\JsBlock::end() ?>
